<template>
  <div class="deal">
    <van-nav-bar title="确认订单" left-text="" left-arrow />
    <router-link to="/address">
      <div class="address">
        <div class="info">
          <span class="name">林生</span>
          <span class="phone">13200000000</span>
        </div>
        <div class="inadd">广东省 深圳市 南山区 招商东路xxxx x栋 xxx</div>
        <van-icon name="arrow" class="right" />
      </div>
    </router-link>
    <div class="detail">
      <p class="shopname">
        <van-icon name="shop-o" class="icon" />水平有限螺蛳粉
      </p>
      <div class="com-in">
        <div class="com-info">
          <img
            :src="deal.img"
            class="com-img"
          />
          <div class="info-in">
            <p class="desc">{{ deal.desc }}</p>
            <span class="in-price">¥{{ deal.price }}</span>
            <span class="in-count">x{{ deal.count }}</span>
            <span class="in-size">{{ deal.size }}</span>
          </div>
        </div>
        <div class="com-sel count">
          数量：
          <div class="com-num">
            <button @click="redcom()" class="red">-</button>
            <span>{{ deal.count }}</span>
            <button @click="addcom()" class="add">+</button>
          </div>
        </div>
        <div class="com-sel freight">
          运费： <span class="in-freight">包邮</span>
        </div>
        <div class="com-sel total">
          合计： <span class="in-total">¥{{ totalPrice }}</span>
        </div>
        <div class="com-sel tips">
          <input type="text" placeholder="写留言" />
        </div>
      </div>
    </div>
    <div class="coupon">
      <van-coupon-cell
        :coupons="coupons"
        :chosen-coupon="chosenCoupon"
        @click="showList = true"
      >
      </van-coupon-cell>
      <!-- 优惠券列表 -->
      <van-popup
        v-model="showList"
        round
        position="bottom"
        style="height: 90%; padding-top: 4px"
      >
        <van-coupon-list
          :coupons="coupons"
          :chosen-coupon="chosenCoupon"
          :disabled-coupons="disabledCoupons"
          @change="onChange"
          @exchange="onExchange"
        />
      </van-popup>
    </div>
    <div class="paytext">支付方式</div>
    <div class="payway">
      <van-radio-group v-model="radio">
        <van-radio name="1" checked-color="#fb6650"
          ><img src="./images/zfb.png" /> 支付宝</van-radio
        >
        <van-radio name="2" checked-color="#fb6650"
          ><img src="./images/wechat.png" /> 微信支付</van-radio
        >
      </van-radio-group>
    </div>
    <div class="pay">
      <div class="right">
        <span class="pay-pri">实付款：¥{{ totalPrice }}</span>
        <button class="pay-btn" @click="toComplete()">付款</button>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations, mapState, mapGetters } from "vuex";
const coupon = {
  available: 0,
  condition: "无使用门槛\n最多优惠12元",
  reason: "",
  value: 150,
  name: "优惠券名称",
  startAt: 1489104000,
  endAt: 1514592000,
  valueDesc: "1.5",
  unitDesc: "元",
};
export default {
  data() {
    return {
      chosenCoupon: -1,
      coupons: [coupon],
      disabledCoupons: [coupon],
      showList: false,
      radio: "1",
    };
  },
  methods: {
    ...mapMutations(["addcom", "redcom"]),
    onChange(index) {
      this.showList = false;
      this.chosenCoupon = index;
    },
    onExchange(code) {
      this.coupons.push(coupon);
    },
    toComplete(){
      this.$router.push("/complete")
    }
  },
  computed: {
    ...mapState(["deal"]),
    ...mapGetters(["totalPrice"]),
  },
};
</script>

<style lang="less" scoped>
.deal {
  background-color: #fbfaf9;
  .van-nav-bar {
    .van-icon {
      color: #333;
      font-size: 22px;
    }
  }
  .address {
    background-color: #d7e5e2;
    height: 1.4rem;
    width: 100%;
    color: #333;
    position: relative;
    padding: 0.16rem;
    box-sizing: border-box;
    font-size: 0.28rem;
    .info {
      overflow: hidden;
      .name {
        float: left;
      }
      .phone {
        float: right;
        margin-right: 0.2rem;
      }
    }
    .inadd {
      position: absolute;
      bottom: 0.24rem;
      left: 0.16rem;
    }
    .right {
      position: absolute;
      right: 0.08rem;
      top: 45%;
      font-size: 0.4rem;
    }
  }
  .detail {
    margin-top: 0.12rem;
    font-size: 0.26rem;
    background-color: #fff;
    .shopname {
      margin: 0.1rem 0;
      height: 0.6rem;
      line-height: 0.6rem;
      padding-left: 0.16rem;
      .icon {
        font-size: 0.36rem;
        vertical-align: -0.04rem;
      }
    }
    .com-in {
      padding: 0 0.16rem 0.18rem;
      overflow: hidden;
      .com-info {
        overflow: hidden;
        .com-img {
          width: 1.4rem;
          height: 1.4rem;
          float: left;
          border-radius: 0.12rem;
        }
        .info-in {
          float: left;
          margin-left: 0.08rem;
          box-sizing: border-box;
          height: 1.56rem;
          position: relative;
          .desc {
            margin: 0;
            width: 72%;
          }
          span {
            position: absolute;
          }
          .in-price {
            right: 0;
            top: 0.04rem;
          }
          .in-count {
            right: 0;
            top: 0.4rem;
            color: #acaca7;
          }
          .in-size {
            left: 0;
            bottom: 0.2rem;
            color: #acaca7;
          }
        }
      }
      .com-sel {
        height: 0.7rem;
        line-height: 0.7rem;
        font-size: 0.28rem;
        position: relative;
        .com-num {
          float: right;
          height: .4rem;
          line-height: .4rem;
          border: 1px solid #333;
          border-radius: .06rem;
          button {
            width: 0.5rem;
            height: 0.4rem;
            padding: 0;
            line-height: 0.4rem;
            border: none;
            background: #fff;
            outline: unset;
          }
          .red{
            border-right: 1px solid #333;
          }
          .add{
            border-left: 1px solid #333;
          }
          span {
            position: unset;
            padding: 0 0.1rem;
          }
        }
        span {
          position: absolute;
          top: 50%;
          transform: translateY(-50%);
          right: 0;
        }
      }
      .freight {
        span {
          color: #acaca7;
        }
      }
      .tips {
        line-height: 0;
        padding-right: 0.16rem;
        input {
          border: none;
          background-color: #ecebe3;
          width: 100%;
          height: 100%;
          border-radius: 0.08rem;
          padding-left: 0.14rem;
          font-size: 0.26rem;
        }
      }
      .count {
        .stepper {
          float: right;
        }
      }
    }
  }
  .coupon {
    margin-top: 0.2rem;
  }
  .paytext {
    padding: 0 0.2rem 0.12rem;
    font-size: 0.26rem;
    margin-top: 0.3rem;
  }
  .payway {
    // background-color: #fff;
    .van-radio {
      height: 1rem;
      line-height: 1rem;
      margin-bottom: .08rem;
      background-color: #fff;
      img {
        height: 0.8rem;
        width: 0.8rem;
        vertical-align: -14px;
      }
    }
  }
  .pay {
    height: 1rem;
    line-height: 1rem;
    position: fixed;
    bottom: 0;
    width: 100%;
    font-size: .26rem;
    border-top: 1px solid rgb(180, 180, 180);
    color: #fb6650;
    ::before{
      content: '';
      display: block;
      width: .1rem;
      position: absolute;
      left: 0;
      top: 0;
      height: .78rem;
      background-color: #fb6650;
    }
    .right{
      float: right;
      .pay-btn{
        padding: 0rem;
        width: 1.4rem;
        height: .7rem;
        margin-right: .3rem;
        border: none;
        outline: unset;
        background-color: #fb6650;
        color: #fff;
        line-height: .7rem;
        margin-left: .1rem;
      }
    }
  }
}
</style>